﻿#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

#endregion

#region COPYRIGHT

/*
    Copyright (c) 2007, 2008, 2009, 2010 
        Roland Rosenkranz (Glatzemann@email.de)
*/

#endregion

#region LICENSE

/*
    This file is part of starLiGHT.Input.

    starLiGHT.Input is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    starLiGHT.Input is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with starLiGHT.Input.  If not, see <http://www.gnu.org/licenses/>.

    
    ADDITIONAL (commercial) LICENSES for starLiGHT.Input are available on request.
*/

#endregion

#region Version Stuff
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 1496                  $:  Revision of last commit *
// * $Author:: glatzemann         $:  Author of last commit   *
// * $Date:: 2010-10-11 09:38:05 #$:  Date of last commit     *
// ************************************************************
#endregion

namespace starLiGHT.Input
{

    /// <summary>
    /// Named index of a logical player. <see>starLiGHT.Input.LogicalPlayer</see>
    /// </summary>
    public enum LogicalPlayerIndex
    {
        /// <summary>
        /// first logical player
        /// </summary>
        One,
        /// <summary>
        /// second logical player
        /// </summary>
        Two,
        /// <summary>
        /// third logical player
        /// </summary>
        Three,
        /// <summary>
        /// fourth logical player
        /// </summary>
        Four
    }

    /// <summary>
    /// The XBox is capable of handling four XBox-Controllers at once. These controllers are numbered 
    /// from one to four which is equal to the port each controller is connected to. If there's more 
    /// than one controller connected to the XBox there's a little problem: The InputManager and your 
    /// game are not able to know which controller the player is using. If he always picks up the 
    /// controller connected to port one everything is fine and this is how many games handle input. 
    /// The starLiGHT.Engine will assist you to make it better by using the concept of logical players.
    /// </summary>
    public static class LogicalPlayer
    {
        private static readonly PlayerIndex[] playerIndices = { PlayerIndex.One,
                                                                PlayerIndex.Two,
                                                                PlayerIndex.Three,
                                                                PlayerIndex.Four,
                                                              };

        /// <summary>
        /// Gets the "physical" index of the player with the given LogicalPlayer index.
        /// </summary>
        /// <param name="index">LogicalPlayer to be returned.</param>
        /// <returns>The "physical" index of the player</returns>
        public static PlayerIndex GetPlayerIndex(LogicalPlayerIndex index)
        {
            return playerIndices[(int)index];
        }

        /// <summary>
        /// Maps a logical player to a "physical" player.
        /// </summary>
        /// <param name="logicalIndex">The logical index of the player to be mapped.</param>
        /// <param name="playerIndex">The "physical" index of the player to be mapped.</param>
        public static void SetPlayerIndex(LogicalPlayerIndex logicalIndex, PlayerIndex playerIndex)
        {
            playerIndices[(int)logicalIndex] = playerIndex;
        }
    }
}
